package edu.calvin.djs32.cs214.interpreters.drivers;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTreeNodeStream;

import edu.calvin.cs214.hobbes2008.HobbesTIR;
import edu.calvin.djs32.cs214.interpreters.calculator.Calculator;
import edu.calvin.djs32.cs214.interpreters.calculator.CalculatorFactory;
import edu.calvin.djs32.cs214.interpreters.frontend.Hobbes2008FrontEnd;
import edu.calvin.djs32.cs214.interpreters.frontend.Hobbes2008TIRBuilder;
import edu.calvin.djs32.cs214.interpreters.prettyprinter.HTMLGenerator;
import edu.calvin.djs32.cs214.interpreters.prettyprinter.PrettyPrinter;

public class PrettyPrintedCalculatorCLIDriver {
	public static void main(String[] args) throws RecognitionException, IOException{
        Calculator calculator = new CalculatorFactory().createCalculator();
        HobbesTIR tree = new Hobbes2008FrontEnd().process(new ANTLRFileStream("calcinput.hob"));
        PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter("tempinput.hob")));
        output.println(new Hobbes2008TIRBuilder(new CommonTreeNodeStream(tree)).expression().accept(calculator));
        output.close();
        HobbesTIR process = new Hobbes2008FrontEnd().process(new ANTLRFileStream("tempinput.hob"));
        PrettyPrinter printer = new PrettyPrinter(new HTMLGenerator());
        PrettyPrinterCLIDriver.generateOutput(printer, process);
	}

}
